/**
 * 线程不安全设计
 */
import sdk from '@/sdk/index'

class ReportService{

  constructor(){
    this._cnt = 0
  }
  load(reportDataId,callbackfn){
    let that = this
    this._cnt ++
    sdk.fetch({
      api:'/publics/reportData/get',
      data:{id:reportDataId},
      success:res=>{
        if(res.state === 3){
          this._cnt == 0
          callbackfn(res)
        }else{
          if(this._cnt < 3){
            that.load(reportDataId,callbackfn)
          }else
            alert('加载失败!')
        }
      },
      fail:err=>{
        console.log(err)
      }
    })
  }
}

export default new ReportService()
